import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class RefreshHeader extends Header {
  @override
  Widget contentBuilder(
      BuildContext context,
      RefreshMode refreshState,
      double pulledExtent,
      double refreshTriggerPullDistance,
      double refreshIndicatorExtent,
      AxisDirection axisDirection,
      bool float,
      Duration completeDuration,
      bool enableInfiniteRefresh,
      bool success,
      bool noMore) {
    return RefreshHeaderWidget(refreshState: refreshState);
  }

  RefreshHeader()
      : super(
          extent: 160.h,
          triggerDistance: 160.h,
          enableHapticFeedback: true,
          completeDuration: Duration(milliseconds: 1),
        );
}

class RefreshHeaderWidget extends StatefulWidget {
  final RefreshMode refreshState;

  const RefreshHeaderWidget({Key key, this.refreshState}) : super(key: key);

  @override
  _RefreshHeaderWidgetState createState() => _RefreshHeaderWidgetState();
}

class _RefreshHeaderWidgetState extends State<RefreshHeaderWidget> with SingleTickerProviderStateMixin {

  @override
  void initState() {
    super.initState();
    print("initState");


  }

  // 可以根据不同状态返回不同widget，来实现刷新。
  @override
  Widget build(BuildContext context) {

    return Container(
      height: double.infinity,
      color: Colors.grey,
      child: Stack(
        alignment: Alignment.bottomCenter,
        children: <Widget>[
          Container(
            alignment: Alignment.center,
            height: 160.h,
            width: double.infinity,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Transform.translate(
                  offset: Offset(0, 0),
                  child: ClipOval(
                    child: Container(
                      height: 15.w,
                      width: 15.w,
                      color: Colors.red,
                    ),
                  ),
                ),
                SizedBox(
                  width: 15.w,
                ),
                ClipOval(
                  child: Container(
                    height: 15.w,
                    width: 15.w,
                    color: Colors.blue,
                  ),
                ),
                SizedBox(
                  width: 15.w,
                ),
                ClipOval(
                  child: Container(
                    height: 15.w,
                    width: 15.w,
                    color: Colors.green,
                  ),
                ),
                SizedBox(
                  width: 15.w,
                ),
                ClipOval(
                  child: Container(
                    height: 15.w,
                    width: 15.w,
                    color: Colors.yellow,
                  ),
                ),
                SizedBox(
                  width: 15.w,
                ),
                ClipOval(
                  child: Container(
                    height: 15.w,
                    width: 15.w,
                    color: Colors.orange,
                  ),
                ),
                SizedBox(
                  width: 15.w,
                ),
              ],
            ),
          )
        ],
      ),
    );
  }

}
